<template xmlns="http://www.w3.org/1999/html">
    <!--新建-->
    <smart-form ref="form_create" method="POST" url="/sys/dic/config/info"
                :model="form_data" :on-succeed="onSubmit">
      <smart-form-layout require name="id" label="ID">
        <smart-text-view name="id" placeholder="唯一ID"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="schemaName" label="数据库名">
        <smart-text-view name="schemaName" placeholder="数据库名" value="med"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="tableName" label="表名">
        <smart-text-view name="tableName" placeholder="表名"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="columnName" label="列名">
        <smart-text-view name="columnName" placeholder="列名"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="columnAlias" label="别名">
        <smart-text-view name="columnAlias" placeholder="别名"></smart-text-view>
      </smart-form-layout>
      <smart-form-layout require name="defaultStyle" label="默认样式">
        <smart-text-view name="defaultStyle" placeholder="默认样式"></smart-text-view>
      </smart-form-layout>
    </smart-form>
</template>

<script>

/**
 * 操作面板
 */
export default {
    components: {}
    , props: {
        // 成功回调，通常是刷新数据表格
        onSucceed: {type: Function, default: undefined}
    }
    , data() {
        return {
            // 操作名称
            operation: undefined
            // 当前操作的行级对象
            , row_data: undefined

            // form-data start 表单数据对象模型
            , form_data: [
                {
                    name: 'id', label: 'ID', value: ''
                    , rules: [
                        {required: true, message: '[ID]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 16, message: '最多16字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'schemaName', label: '库名', value: ''
                    , rules: [
                        {required: true, message: '[库名]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 64, message: '最多64字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'tableName', label: '表名', value: ''
                    , rules: [
                        {required: true, message: '[表名]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 64, message: '最多64字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'columnName', label: '列名', value: ''
                    , rules: [
                        {required: true, message: '[列名]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 64, message: '最多64字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'columnAlias', label: '列别名', value: ''
                    , rules: [
                        {required: true, message: '[列别名]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 32, message: '最多32字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'defaultStyle', label: '默认样式', value: ''
                    , rules: [
                        {required: true, message: '[默认样式]字段不允许为空 ', trigger: 'blur'},
                        {min: 0, max: 32, message: '最多32字符', trigger: 'blur'}
                    ]
                },
                {
                    name: 'editable', label: '是否可编辑', value: ''
                },
            ]
            // form-data end
        }
    }
    , methods: {
        /**
         * 新增/编辑操作成功，关闭当前窗口
         *
         * @param ret 后台响应数据
         */
        onSubmit: function (ret) {
            this.$refs.dialog.close();
            if (ret.code === 0) {
                this.$layers.succeed();
            }
            if (this.onSucceed !== undefined) {
                this.onSucceed(ret);
            }
        }
        /**
         * 操作栏事件分发
         * @param evt 事件
         * @param row 行级对象
         * @param old 可供回滚的参数
         */
        , onAction: function (evt, row, old) {
            this.operation = evt;
            if (evt === 'new') {
                let dialog = {title: `新建`};
                this.$refs.dialog.open(dialog);
            } else if (evt === 'dic') {
                let dialog = {title: `管理键值`, width: '50%', fullscreen: true};
                this.$refs.dialog.open(dialog).then(() => this.row_data = row);
            }
        }
    }
}
</script>
